﻿using System;

namespace ProtetoresDaMata.Data
{
    public class DataInit
    {

        public DataInit()
        {
            InitializeData();
        }

        private void InitializeData()
        {
            using (GameDataContext context = new GameDataContext())
            {

                if (!context.DatabaseExists())
                {
                    // create database if it does not exist
                    context.CreateDatabase();


                    //Score Accumulated of all games
                    Score scoreTotal = new Score();

                    scoreTotal.Date = DateTime.Now;
                    scoreTotal.PointsScore = 0;
                    scoreTotal.DistanceScore = 0;
                    scoreTotal.PlayerName = "PointsAccumulated";

                    context.GetTable<Score>().InsertOnSubmit(scoreTotal);
                    context.SubmitChanges();

                    for (int i = 1; i < 10; i++)
                    {
                        Score score = new Score();

                        score.Date = DateTime.Now.AddDays(i * -1);
                        score.PointsScore = (int)((new Random()).NextDouble() * 10000);
                        score.DistanceScore = (int)((new Random()).NextDouble() * 100);
                        score.PlayerName = "Indio " + i.ToString();

                        context.GetTable<Score>().InsertOnSubmit(score);
                        context.SubmitChanges();

                    }
                }
            }
        }

    }
}
